﻿@inject IStringLocalizer<EditFormSkipValidate> Localizer

<GroupBox Title="@Localizer["GroupBoxTile"]">
    <p>@((MarkupString)Localizer["SkipValidateDescription"].Value)</p>
    <ValidateForm Model="Model">
        <EditorForm Model="Model" AutoGenerateAllItem="false">
            <FieldItems>
                <EditorItem @bind-Field="@context.Name" />
                <EditorItem @bind-Field="@context.Address" />
                <EditorItem @bind-Field="@context.Count">
                    <EditTemplate Context="value">
                        <div class="col-12 col-sm-6">
                            <Select SkipValidate="true" @bind-Value="@value.Count" Items="@DummyItems" ShowSearch="true" />
                        </div>
                        <div class="col-12 col-sm-6">
                            <BootstrapInput Value="@value.Count" Readonly="true" />
                        </div>
                    </EditTemplate>
                </EditorItem>
                <EditorItem @bind-Field="@context.Hobby" Items="@Hobbys" />
            </FieldItems>
            <Buttons>
                <Button ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" Text="@Localizer["SubButtonText"]" />
            </Buttons>
        </EditorForm>
    </ValidateForm>
</GroupBox>

@code {
    /// <summary>
    /// Foo 类为Demo测试用，如有需要请自行下载源码查阅
    /// Foo class is used for Demo test, please download the source code if necessary
    /// https://gitee.com/LongbowEnterprise/BootstrapBlazor/blob/main/src/BootstrapBlazor.Shared/Data/Foo.cs
    /// </summary>
    [NotNull]
    private Foo? Model { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Hobbys { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<Foo>? FooLocalizer { get; set; }

    private List<SelectedItem> DummyItems { get; } = new List<SelectedItem>()
    {
        new SelectedItem("1", "1"),
        new SelectedItem("2", "2"),
        new SelectedItem("3", "3"),
        new SelectedItem("4", "4"),
        new SelectedItem("5", "5")
    };

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Hobbys = Foo.GenerateHobbys(FooLocalizer);
        Model = new Foo()
        {
            Name = Localizer["TestName"],
            Count = 1,
            Address = Localizer["TestAddr"],
            DateTime = new DateTime(1997, 12, 05),
            Education = EnumEducation.Middle
        };
    }
}
